//全屏
var btn = document.getElementById("btn");
 
btn.onclick = function() {
    var width =  window.screen.width;
    var height =   window.screen.height;
    var allbody = document.getElementById("allbody");
    requestFullScreen(allbody);
}
 
function requestFullScreen(element) {
    if (element.requestFullscreen) {
        element.requestFullscreen();
    }
//FireFox
    else if (element.mozRequestFullScreen) {
        element.mozRequestFullScreen();
    }
//Chrome等
    else if (element.webkitRequestFullScreen) {
        element.webkitRequestFullScreen();
    }
//IE11
    else if (element.msRequestFullscreen) {
        element.msRequestFullscreen();
    }
};
//鼠标放在诺依的头像上隐藏的内容会出现
var a=document.getElementById("hidePerson");
function showPerson(){
	a.style.display="block";
	a.style.opacity="1";
	a.style.transition="1s";
}
function offPerson(){
	a.style.display="none";
	a.style.opacity="0";
	a.style.transition="0";	
}
//修改个人信息
//var changeInfor=document.getElementById("changeInfor");
//var altertext=document.getElementsByClassName("altertext");
//var alterHide=document.getElementsByClassName("alterHide")[0];
//var alterYesBtn=document.getElementsByClassName("alterYesBtn")[0];
//var alterNoBtn=document.getElementsByClassName("alterNoBtn")[0];
//	changeInfor.onclick=function(){
//		alterHide.style.display="block";
//		altertext[0].value="若依";
//		altertext[1].value="hhhhhhhh";
//		altertext[2].value= "13413148888";
//		altertext[3].value="25";
//		altertext[4].value="女";
//		
//		alterYesBtn.onclick=function(){
//			$.ajax({
//				url:"http://118.195.129.130:3000/user/mod_head",
//				type:"post",
//				async:true,
//				data:{
//					us:altertext[0].value,
//					_id:altertext[1].value,
//					phone:altertext[2].value,
//					age:altertext[3].value,
//					sex:altertext[4].value,
//				},
//				success:function(data){
//					alterHide.style.display="none";
//					console.log(data)
//				},
//				error:function(err){
//					console.log("错误");
//				}
//			});
//		}
//		alterNoBtn.onclick=function(){
//			alterHide.style.display="none";
//		}
//
//	}
	
//给tbody里面传入数据
//page();
//var secondTables=document.getElementById("secondTables");
//var dish=document.getElementsByClassName("dish");
//var jiPage=document.getElementsByClassName("jiPage")[0];
//
//function page(i){
//	$.ajax({
//		type:"post",
//		url:"http://118.195.129.130:3000/food/getInfoByPage",
//		async:true,
//		data:{
//			page:i,
//			per_page:5
//		},
//		success:function(data){
//			for(let i=0;i<dish.length;i++){
//				dish[i].children[0].innerHTML = data.data[i].name;
//              dish[i].children[1].innerHTML = data.data[i].price;
//              dish[i].children[2].innerHTML = data.data[i].desc;
//              dish[i].children[3].innerHTML = data.data[i].typename;
//              dish[i].children[4].innerHTML = data.data[i].typeid;
//			}
//		},
//		error:function(err){
//			console.log("错误");
//		}
//	})
//			
//}
//增加一行,就是创建表格
var secondTablesTr = document.getElementsByClassName('secondTablesTr');
var secondTables=document.getElementById("secondTables");
function addTr(){
	var createTr=document.createElement('tr');
	createTr.className='secondTablesTr';
	secondTables.appendChild(createTr);
	for(let i=0;i<6;i++){
		if(i==5){
			var createTd=document.createElement('td');
			createTd.innerHTML="<button class='del'>删除<button class='change'>修改"
			createTd.className='secondTablesTd';
			createTr.appendChild(createTd);
		}else{
			var createTd=document.createElement('tr');
			createTd.className='secondTablesTd';
			createTr.appendChild(createTd);
		}
	}	
}
//向表格里面传入数据
//function secondTables{
	$.ajax({
		url:"http://118.195.129.130:3000/food/getInfoByPage",
		type:"post",
		data:{
			page:jiPage.value,
			per_page:5
		},
		success:function(data){
			
			for(let i=0;i<data.data.length;i++){
				addTr();
				secondTablesTr[i].children[0].innerHTML = data.data[i].name;
                secondTablesTr[i].children[1].innerHTML = data.data[i].price;
                secondTablesTr[i].children[2].innerHTML = data.data[i].desc;
                secondTablesTr[i].children[3].innerHTML = data.data[i].typename;
                secondTablesTr[i].children[4].innerHTML = data.data[i].typeid;
			}
		}
	})
//}
//换页
var allPage=document.getElementsByClassName("allPage")[0];
getAllPage();
function getAllPage(){
	$.ajax({
		type:"get",
		url:"http://118.195.129.130:3000/food/allpage",
		async:true,
		data:{
			
		},
		success:function(data){
			if(data.pages%5==0){
				data.pages/=10;
			}else{
				data.pages=parseInt(data.pages/5)+1;
			}
			allPage.innerHTML=data.pages;
			
		},
		error:function(err){
			console.log("错误");
		}
	})
}
//分页查询
var jiPage=document.getElementsByClassName("jiPage")[0];
var secondTablesTr=document.getElementsByClassName("secondTablesTr");
showDishes();//使页面加载出来的时候表格里面有内容
var allPage=document.getElementsByClassName("allPage")[0];
var secondTables=document.getElementById("secondTables");
function showDishes(){
	$.ajax({
		type:"post",
		url:"http://118.195.129.130:3000/food/getInfoByPage",
		data:{
			page:jiPage.value,
			per_page:5
		},
		success:function(data){
			for(let i=0;i<data.data.length;i++){
				addTr();
				secondTablesTr[i].children[0].innerHTML=data.data[i].name;
				secondTablesTr[i].chilidren[1].innerHTML=data.data[i].price;
				secondTablesTr[i].children[2].innerHTML=data.data[i].desc;
				secondTablesTr[i].children[3].innerHTML=data.data[i].typename;
				secondTablesTr[i].children[4].innerHTML=data.data[i].typeid;
			}
		},
		error:function(){
			console.log("错误");
		}
	})
}

//下一页
var nextPage=document.getElementsByClassName("nextPage")[0];
nextPage.onclick=function(){
	$.ajax({
		type:"get",
		url:"http://118.195.129.130:3000/food/allpage",
		async:true,
		success:function(data){
			if(jiPage.value>=(data.pages/5)){
				alert("页数过大，请重新输入！")
				return;
			}else{
				jiPage.value++;
				page(jiPage.value);
			}
			if(isNaN(Number(jiPage.value))){
				alert("请输入数字!")
				jiPage.value=1;
			}
		},
		error:function(err){
			alert(data.msg);
		}
	})
}
//上一页
var backPage=document.getElementsByClassName("backPage")[0];
backPage.onclick=function(){
	$.ajax({
		type:"get",
		url:"http://118.195.129.130:3000/food/allpage",
		async:true,
		success:function(data){
			if(jiPage.value>=(data.pages/5)||jiPage.value<=1){
				alert("页数不在此范围，请重新输入！")
				return;
			}else{
				jiPage.value-=1;
				page(jiPage.value);
			}
			if(isNaN(Number(jiPage.value))){
				alert("请输入数字!")
				jiPage.value=1;
			}
		},
		error:function(err){
			alert(data.msg);
		}
	})
}

